package doudizhu;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


public class Doudizhu {
    //声明一副扑克牌
    public static ArrayList<Card> poker = new ArrayList<>();
    public static String[] points = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER"};
    public static String[] type = {"♦", "♣", "♥", "♠"};

    public  static MyComparator comparator = new MyComparator();

    // 初始化54张扑克牌
    public void init() {
        int value = 0;
        for (int i = 0; i < points.length; i++) {
            if (i < 13) {
                for (int j = 0; j < type.length; j++) {
                    Card card = new Card(points[i], type[j], value);
                    poker.add(card);
                    value++;
                }
            } else {
                Card card = new Card(points[i], "", value);
                poker.add(card);
                value++;
            }
        }
    }

    // 洗牌
    public void xipai() {
        Collections.shuffle(poker);
    }

    // 发牌
    public void fapai() {
        List<Card> player1 = poker.subList(0, 17);
        List<Card> player2 = poker.subList(17, 34);
        List<Card> player3 = poker.subList(34, 51);
        List<Card> landlord = poker.subList(51, 54);

        System.out.println("玩家1" + player1);
        System.out.println("玩家2" + player2);
        System.out.println("玩家3" + player3);
        System.out.println("地主牌" + landlord);

        player1.sort(comparator);
        player2.sort(comparator);
        player3.sort(comparator);
        landlord.sort(comparator);

        System.out.println("排序后");;
        System.out.println("玩家1" + player1);
        System.out.println("玩家2" + player2);
        System.out.println("玩家3" + player3);
        System.out.println("地主牌" + landlord);
    }


    //排序
    public void sort(MyComparator comparator) {

    }

    public static void main(String[] args) {
        Doudizhu doudizhu = new Doudizhu();
        doudizhu.init();
        System.out.println(poker);
        doudizhu.xipai();
        System.out.println("洗牌后");
        System.out.println(poker);
        doudizhu.fapai();

    }
}
